package com.atguigu;

import jdk.nashorn.internal.objects.annotations.Getter;

import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;


class User{
    String username;
    int age;
    public User() {
    }

    public User(String username, int age) {
        this.username = username;
        this.age = age;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "username='" + username + '\'' +
                ", age=" + age +
                '}';
    }
}
public class ABADemo {
    static  AtomicReference<Integer> atomicReference=new AtomicReference<>(100);
    public static void main(String[] args) {
//        User z3=new User("z3",22);
//        User li4=new User("li4",25);
//        AtomicReference<User> atomicReference=new AtomicReference<>();
//        atomicReference.set(z3);
//        System.err.println(atomicReference.compareAndSet(z3, li4)+"\t"+atomicReference.get().toString());
//        System.err.println(atomicReference.compareAndSet(z3, li4)+"\t"+atomicReference.get().toString());
            new Thread(()->{
                atomicReference.compareAndSet(100,101);
                atomicReference.compareAndSet(101,100);
            },"t1").start();
            new Thread(()->{
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.err.println(atomicReference.compareAndSet(100, 2019)+"\t"+atomicReference.get());
            },"ccc").start();
    }
}
